interface Rect {
    maxX: number;
    minX: number;
    maxY: number;
    minY: number;
}

export enum Where {
    Top,
    Right,
    Bottom,
    Left,
}
interface Point {
    x: number;
    y: number;
}
/** 当角色触碰到边界时的回调操作 */
export function keepEdge(
    target: Point,
    { maxX, maxY, minX, minY }: Rect,
    event: (position: Where) => void
) {
    if (target.y < minY) {
        target.y = minY;
        event(Where.Top);
    }
    if (target.x > maxX) {
        target.x = maxX;
        event(Where.Right);
    }
    if (target.y > maxY) {
        target.y = maxY;
        event(Where.Bottom);
    }
    if (target.x < minX) {
        target.x = minX;
        event(Where.Left);
    }
}
